package com.ai.bitcoin.jpa.dao;

import com.ai.bitcoin.jpa.entity.ExchangeUserRel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @description: ${description}
 * @author: gulj
 * @create: 2018-08-06 11:28
 **/
public interface ExchangeUserRelDao extends JpaRepository<ExchangeUserRel, String> {


    List<ExchangeUserRel> findByOpenId(String openId);


    @Query(nativeQuery = true,value = "SELECT * from exchange_user_rel where open_id in (?1) and  FIND_IN_SET(?2,exchange_name) ")
    List<ExchangeUserRel> queryWithMarket(List<String> openIds, String market);


    @Query(nativeQuery = true,value = "UPDATE exchange_user_rel set exchange_name = ?1 where open_id = ?2 ")
    @Modifying
    @Transactional
    void updateExchangeNameByOpenId(String exchangeNames,String openId);

}
